//! Await.debug.js
//

(function() {

Type.registerNamespace('Awaiter');

////////////////////////////////////////////////////////////////////////////////
// Timers

Timers = function Timers() {
    /// <field name="_timers" type="Object">
    /// </field>
    /// <field name="_delayedSpinner" type="Number" integer="true" static="true">
    /// </field>
    this._timers = {};
}
Timers.prototype = {
    
    setTimeout: function Timers$setTimeout(fn, ms) {
        /// <param name="fn" type="Function">
        /// </param>
        /// <param name="ms" type="Number" integer="true">
        /// </param>
        /// <returns type="Number" integer="true"></returns>
        var t = window.setTimeout(fn, ms);
        this._timers[t] = clearTimeout;
        return t;
    },
    
    setInterval: function Timers$setInterval(fn, ms) {
        /// <param name="fn" type="Function">
        /// </param>
        /// <param name="ms" type="Number" integer="true">
        /// </param>
        /// <returns type="Number" integer="true"></returns>
        var t = window.setInterval(fn, ms);
        this._timers[t] = clearInterval;
        return t;
    },
    
    clearTimer: function Timers$clearTimer(timer) {
        /// <param name="timer" type="Number" integer="true">
        /// </param>
        /// <returns type="Number" integer="true"></returns>
        var fn = this._timers[timer];
        if (fn != null) {
            var ret = fn(timer);
            delete this._timers[timer];
            return ret;
        }
        return 0;
    },
    
    clearAll: function Timers$clearAll() {
        var $dict1 = this._timers;
        for (var $key2 in $dict1) {
            var p = { key: $key2, value: $dict1[$key2] };
            this.clearTimer(p.key);
        }
    },
    
    startDelayedSpinner: function Timers$startDelayedSpinner() {
        return;
        if (Timers._delayedSpinner > 0) {
            return;
        }
        console.log('Starting delayed spinner');
        Timers._delayedSpinner = window.setTimeout(function() {
            Await.trigger('Spinner', true);
        }, 3000);
    },
    
    stopDelayedSpinner: function Timers$stopDelayedSpinner() {
        return;
        console.log('Stopping delayed spinner');
        Await.trigger('Spinner', false);
        var sv = Timers._delayedSpinner;
        Timers._delayedSpinner = 0;
        window.clearTimeout(sv);
    }
}


////////////////////////////////////////////////////////////////////////////////
// WaitTarget

WaitTarget = function WaitTarget() {
    /// <field name="fn" type="Function">
    /// </field>
    /// <field name="targetMs" type="Number" integer="true">
    /// </field>
}
WaitTarget.prototype = {
    fn: null,
    targetMs: 0
}


////////////////////////////////////////////////////////////////////////////////
// Await

Await = function Await() {
    /// <field name="logActions" type="Boolean" static="true">
    /// </field>
    /// <field name="passExceptions" type="Boolean" static="true">
    /// </field>
    /// <field name="_scripts" type="Object" static="true">
    /// </field>
    /// <field name="_simulatedLatency" type="Number" integer="true" static="true">
    /// </field>
    /// <field name="files" type="Object" static="true">
    /// </field>
    /// <field name="timer" type="Timers">
    /// </field>
    /// <field name="vars" type="Object">
    /// </field>
    /// <field name="varsModified" type="Object">
    /// </field>
    /// <field name="_traceList" type="Array">
    /// </field>
    /// <field name="events" type="Object">
    /// </field>
    /// <field name="_abort" type="Boolean">
    /// </field>
    /// <field name="_alwaysAction" type="Function">
    /// </field>
    /// <field name="_awp" type="Await">
    /// </field>
    /// <field name="_count" type="Number" integer="true">
    /// </field>
    /// <field name="_exceptionHandlers" type="Object">
    /// </field>
    /// <field name="_ignore" type="Boolean">
    /// </field>
    /// <field name="_maxWaitStyleSheet" type="Number" integer="true">
    /// </field>
    /// <field name="_parallelActions" type="Array">
    /// </field>
    /// <field name="_queCount" type="Number" integer="true">
    /// </field>
    /// <field name="_serialActions" type="Array">
    /// </field>
    /// <field name="_serialSaved" type="Array">
    /// </field>
    /// <field name="_thrown" type="Error">
    /// </field>
    this.timer = new Timers();
    this.vars = {};
    this.varsModified = {};
    this._traceList = [];
}
Await.get_asyncAw = function Await$get_asyncAw() {
    /// <value type="Await"></value>
    return new Await();
}
Await.trigger = function Await$trigger(nm, arg) {
    /// <param name="nm" type="String">
    /// </param>
    /// <param name="arg" type="Object">
    /// </param>
    var args = new Array(1);
    args[0] = arg;
    $(document).trigger(nm, args);
}
Await.vita = function Await$vita(key, record) {
    /// <param name="key" type="String">
    /// </param>
    /// <param name="record" type="String">
    /// </param>
    /// <returns type="Object"></returns>
    return (Await.files[key])[record];
}
Await.abortAw = function Await$abortAw(aw) {
    /// <param name="aw" type="Await">
    /// </param>
    aw.abort();
}
Await.ignoreAw = function Await$ignoreAw(aw) {
    /// <param name="aw" type="Await">
    /// </param>
    aw.done();
}
Await.finishAw = function Await$finishAw(aw) {
    /// <param name="aw" type="Await">
    /// </param>
    aw.finish();
}
Await.rethrowAw = function Await$rethrowAw(aw) {
    /// <param name="aw" type="Await">
    /// </param>
    aw._ignore = true;
    aw._doAlways(function() {
        if (aw.get_awp() != null && aw._thrown != null) {
            aw._proxyVars();
            aw.get_awp().handle(aw._thrown);
        }
    });
}
Await.fileDictionary = function Await$fileDictionary(key) {
    /// <param name="key" type="String">
    /// </param>
    /// <returns type="Object"></returns>
    return Await.files[key];
}
Await.prototype = {
    events: null,
    _abort: false,
    _alwaysAction: null,
    _awp: null,
    _count: 0,
    _exceptionHandlers: null,
    _ignore: false,
    _maxWaitStyleSheet: 20000,
    _parallelActions: null,
    _queCount: 0,
    _serialActions: null,
    _serialSaved: null,
    _thrown: null,
    
    get_result: function Await$get_result() {
        /// <value type="Object"></value>
        return this.get_item('result');
    },
    set_result: function Await$set_result(value) {
        /// <value type="Object"></value>
        this.set_item('result', value);
        return value;
    },
    
    get_awp: function Await$get_awp() {
        /// <value type="Await"></value>
        return this._awp;
    },
    
    _doAlways: function Await$_doAlways(fn) {
        /// <param name="fn" type="System.Action`1">
        /// </param>
        var my = this;
        if (this._alwaysAction == null) {
            fn(my);
            return;
        }
        this.timer.setTimeout(ss.Delegate.create(this, function() {
            this._alwaysAction(my);
            fn(my);
        }), 1);
    },
    
    handle: function Await$handle(ex) {
        /// <param name="ex" type="Error">
        /// </param>
        var exType = ((ss.isValue(ex.message)) ? ex.message : 'none').split(':')[0].trim();
        if (this._exceptionHandlers != null && Object.keyExists(this._exceptionHandlers, exType)) {
            this._trace(String.format('Handling await exception: {0}', ex));
            var fn = this._exceptionHandlers[exType];
            this._thrown = ex;
            fn(this);
            return;
        }
        switch (exType) {
            default:
                if (this._awp != null) {
                    this._proxyVars();
                    this._awp.handle(ex);
                }
                else {
                    this._error(String.format('Aborting await chain with exception: "{0}"', ex));
                    var trace = printStackTrace({ e: ex, guess: true });
                    var $enum1 = ss.IEnumerator.getEnumerator(trace);
                    while ($enum1.moveNext()) {
                        var line = $enum1.current;
                        this._log(line);
                    }
                    this.abort();
                    throw ex;
                }
                break;
        }
    },
    
    _doAbort: function Await$_doAbort() {
        /// <returns type="Await"></returns>
        this._ignore = true;
        this._doAlways(ss.Delegate.create(this, function() {
            if (this._awp != null) {
                this._proxyVars();
                this._awp.abort();
            }
        }));
        return this;
    },
    
    _actionClosure: function Await$_actionClosure(f) {
        /// <param name="f" type="Function">
        /// </param>
        var my = this;
        this.timer.setTimeout(function() {
            f(my);
        }, 1);
    },
    
    _logDoFn: function Await$_logDoFn(fn, arg1, arg2, arg3) {
        /// <param name="fn" type="Object">
        /// </param>
        /// <param name="arg1" type="Object">
        /// </param>
        /// <param name="arg2" type="Object">
        /// </param>
        /// <param name="arg3" type="Object">
        /// </param>
        if (!Await.logActions) {
            return;
        }
        var t = fn._targets;
        if (ss.isValue(t)) {
            var args = '()';
            if (ss.isValue(arg1)) {
                args = String.format('({0},{1},{2})', arg1, arg2, arg3);
            }
            if (t.length > 1 && ss.isValue(t[1])) {
                var a = fn._targets[1].name;
                if (ss.isValue(a) && !String.isNullOrEmpty(a)) {
                    this._log(String.format('Await doing {0}{1}', a, args));
                }
                else {
                    a = Type.getInstanceType(fn._targets[0]).get_name();
                    this._log(String.format('Await doing (anonymous delegate){0}{1}', a, args));
                }
            }
        }
    },
    
    _proxyVars: function Await$_proxyVars() {
        if (this._awp != null) {
            var $dict1 = this.vars;
            for (var $key2 in $dict1) {
                var p = { key: $key2, value: $dict1[$key2] };
                if (!this._awp.varsModified[p.key]) {
                    this._awp.vars[p.key] = p.value;
                }
            }
        }
    },
    
    _loadScriptWait: function Await$_loadScriptWait(url) {
        /// <param name="url" type="String">
        /// </param>
        if (!Await._scripts[url]) {
            this.timer.startDelayedSpinner();
            this.timer.setTimeout(ss.Delegate.create(this, function() {
                this._loadScriptWait(url);
            }), 13);
        }
        else {
            this.timer.stopDelayedSpinner();
            this.done();
        }
    },
    
    _log: function Await$_log(msg) {
        /// <param name="msg" type="String">
        /// </param>
        if (window.console) console.log(msg);
    },
    
    _trace: function Await$_trace(msg) {
        /// <param name="msg" type="String">
        /// </param>
    },
    
    _error: function Await$_error(msg) {
        /// <param name="msg" type="String">
        /// </param>
        if (window.console) {
            window.console.error(msg);
        }
    },
    
    que: function Awaiter_Await$que(fn) {
        /// <param name="fn" type="Function">
        /// </param>
        /// <returns type="Await"></returns>
        if (this._parallelActions == null) {
            this._parallelActions = [];
        }
        this._parallelActions.add(ss.Delegate.create(this, function(aw) {
            this._logDoFn(fn);
            if (Await.passExceptions) {
                fn(aw);
                return;
            }
            try {
                fn(aw);
            }
            catch (ex) {
                this.handle(ex);
            }
        }));
        this._count++;
        this._queCount++;
        return this;
    },
    
    addDl: function Awaiter_Await$addDl(fn) {
        /// <param name="fn" type="Function">
        /// </param>
        /// <returns type="Await"></returns>
        if (this._serialSaved == null) {
            this._serialSaved = [];
        }
        this._serialSaved.add(ss.Delegate.create(this, function(aw) {
            this._logDoFn(fn);
            if (Await.passExceptions) {
                fn(aw);
                return;
            }
            try {
                fn(aw);
            }
            catch (ex) {
                this.handle(ex);
            }
        }));
        this._count++;
        return this;
    },
    
    addDx: function Awaiter_Await$addDx(fn) {
        /// <param name="fn" type="Function">
        /// </param>
        /// <returns type="Await"></returns>
        if (this._serialSaved == null) {
            this._serialSaved = [];
        }
        this._serialSaved.add(ss.Delegate.create(this, function(aw) {
            this._logDoFn(fn);
            if (Await.passExceptions) {
                fn(aw);
                aw.done();
                return;
            }
            try {
                fn(aw);
                aw.done();
            }
            catch (ex) {
                this.handle(ex);
            }
        }));
        this._count++;
        return this;
    },
    
    addAw: function Awaiter_Await$addAw(fn, arg1, arg2, arg3) {
        /// <param name="fn" type="System.Action`4">
        /// </param>
        /// <param name="arg1" type="Object">
        /// </param>
        /// <param name="arg2" type="Object">
        /// </param>
        /// <param name="arg3" type="Object">
        /// </param>
        /// <returns type="Await"></returns>
        if (this._serialSaved == null) {
            this._serialSaved = [];
        }
        this._serialSaved.add(ss.Delegate.create(this, function(aw) {
            this._logDoFn(fn, arg1, arg2, arg3);
            if (Await.passExceptions) {
                fn(aw, arg1, arg2, arg3);
                return;
            }
            try {
                fn(aw, arg1, arg2, arg3);
            }
            catch (ex) {
                this.handle(ex);
            }
        }));
        this._count++;
        return this;
    },
    
    queFn: function Awaiter_Await$queFn(fn) {
        /// <param name="fn" type="Function">
        /// </param>
        /// <returns type="Await"></returns>
        this.que(ss.Delegate.create(this, function(aw) {
            this._logDoFn(fn);
            if (Await.passExceptions) {
                fn();
                aw.done();
                return;
            }
            try {
                fn();
                aw.done();
            }
            catch (ex) {
                this.handle(ex);
            }
        }));
        return this;
    },
    
    addFn: function Awaiter_Await$addFn(fn, arg1, arg2) {
        /// <param name="fn" type="System.Action`2">
        /// </param>
        /// <param name="arg1" type="Object">
        /// </param>
        /// <param name="arg2" type="Object">
        /// </param>
        /// <returns type="Await"></returns>
        if (this._serialSaved == null) {
            this._serialSaved = [];
        }
        this._serialSaved.add(ss.Delegate.create(this, function(aw) {
            this._logDoFn(fn, arg1, arg2);
            if (Await.passExceptions) {
                fn(arg1, arg2);
                aw.done();
                return;
            }
            try {
                fn(arg1, arg2);
                aw.done();
            }
            catch (ex) {
                this.handle(ex);
            }
        }));
        this._count++;
        return this;
    },
    
    addEv: function Awaiter_Await$addEv(name, fn) {
        /// <param name="name" type="String">
        /// </param>
        /// <param name="fn" type="Function">
        /// </param>
        /// <returns type="Await"></returns>
        if (this.events == null) {
            this.events = {};
        }
        this.events[name] = fn;
        return this;
    },
    
    doneWith: function Awaiter_Await$doneWith(n, v) {
        /// <param name="n" type="String">
        /// </param>
        /// <param name="v" type="Object">
        /// </param>
        this.vars[n] = v;
        this.done();
    },
    
    done: function Awaiter_Await$done() {
        /// <returns type="Await"></returns>
        if (this._ignore) {
            return this;
        }
        if (this._abort) {
            return this._doAbort();
        }
        if (this._traceList.length > 0) {
            var msg = this._traceList[this._traceList.length - 1];
            this._traceList.removeAt(this._traceList.length - 1);
            this._trace('Done: ' + msg);
        }
        this._count--;
        this._queCount--;
        return this._next();
    },
    
    insertDl: function Awaiter_Await$insertDl(fn) {
        /// <param name="fn" type="Function">
        /// </param>
        /// <returns type="Await"></returns>
        if (!this._abort) {
            ss.Debug.assert(fn != null, 'InsertDl fn != null');
            this._serialActions.insert(0, fn);
            this._count++;
        }
        return this;
    },
    
    always: function Awaiter_Await$always(fn) {
        /// <param name="fn" type="Function">
        /// </param>
        /// <returns type="Await"></returns>
        this._alwaysAction = fn;
        return this;
    },
    
    handleDl: function Awaiter_Await$handleDl(exceptionName, fn) {
        /// <summary>
        /// Handles the specified exception.
        /// </summary>
        /// <param name="exceptionName" type="String">
        /// Name of the exception.
        /// </param>
        /// <param name="fn" type="Function">
        /// The action to perform. Must envoke Done.
        /// </param>
        /// <returns type="Await"></returns>
        if (this._exceptionHandlers == null) {
            this._exceptionHandlers = {};
        }
        this._exceptionHandlers[exceptionName] = fn;
        return this;
    },
    
    handleDx: function Awaiter_Await$handleDx(exceptionName, fn) {
        /// <summary>
        /// Handles the specified exception with automatic Done() being done at the end
        /// </summary>
        /// <param name="exceptionName" type="String">
        /// Name of the exception.
        /// </param>
        /// <param name="fn" type="Function">
        /// The action to perform.
        /// </param>
        /// <returns type="Await"></returns>
        return this.handleDl(exceptionName, ss.Delegate.create(this, function() {
            fn(this);
            this.done();
        }));
    },
    
    abort: function Awaiter_Await$abort() {
        /// <returns type="Await"></returns>
        this._abort = true;
        return this._doAbort();
    },
    
    sleep: function Awaiter_Await$sleep(ms) {
        /// <param name="ms" type="Number" integer="true">
        /// </param>
        /// <returns type="Await"></returns>
        return this.addDl(ss.Delegate.create(this, function() {
            this.timer.setTimeout(ss.Delegate.create(this, function() {
                this.done();
            }), ms);
        }));
    },
    
    _waitAw: function Awaiter_Await$_waitAw(awp, waitTarget) {
        /// <summary>
        /// Waits until a wait target object is satisfied.
        /// </summary>
        /// <param name="awp" type="Await">
        /// The awp.
        /// </param>
        /// <param name="waitTarget" type="Object">
        /// The wait target object
        /// </param>
        var t = waitTarget;
        t.targetMs = (t.targetMs || new Date().getTime() + 10000);
        if (t.fn()) {
            awp.done();
            return;
        }
        if (new Date().getTime() >= t.targetMs) {
            this._log(String.format('WaitAw waited {0} for {1}', t.targetMs, t.fn));
            awp.done();
            return;
        }
        this.timer.setTimeout(ss.Delegate.create(this, function() {
            this._waitAw(awp, t);
        }), 13);
    },
    
    waitDx: function Awaiter_Await$waitDx(fn, maxWaitMs) {
        /// <param name="fn" type="Function">
        /// </param>
        /// <param name="maxWaitMs" type="Number" integer="true">
        /// </param>
        /// <returns type="Await"></returns>
        var t = new WaitTarget();
        t.fn = fn;
        t.targetMs = new Date().getTime() + (maxWaitMs || 10000);
        return this.addAw(ss.Delegate.create(this, this._waitAw), t);
    },
    
    simulateAsync: function Awaiter_Await$simulateAsync() {
        /// <returns type="Await"></returns>
        return this.addDl(ss.Delegate.create(this, function() {
            this.timer.setTimeout(ss.Delegate.create(this, function() {
                this.done();
            }), Await._simulatedLatency);
        }));
    },
    
    commit: function Awaiter_Await$commit(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <returns type="Await"></returns>
        this.timer.clearAll();
        this._ignore = this._abort = false;
        this._awp = (ss.isValue(awp)) ? awp : null;
        if (this._serialSaved != null) {
            this._serialActions = this._serialSaved.clone();
        }
        this._queCount = (this._parallelActions == null) ? 0 : this._parallelActions.length;
        this._count = (this._serialActions == null) ? 0 : this._serialActions.length + this._queCount;
        return this._doActions();
    },
    
    _doActions: function Awaiter_Await$_doActions() {
        /// <returns type="Await"></returns>
        if (this._queCount > 0) {
            var $enum1 = ss.IEnumerator.getEnumerator(this._parallelActions);
            while ($enum1.moveNext()) {
                var f = $enum1.current;
                if (this._abort) {
                    return this._doAbort();
                }
                this._actionClosure(f);
            }
        }
        else {
            this._next();
        }
        return this;
    },
    
    _next: function Awaiter_Await$_next() {
        /// <returns type="Await"></returns>
        if (this._ignore) {
            return this;
        }
        if (this._abort) {
            return this._doAbort();
        }
        var my = this;
        if (this._queCount <= 0 && this._count > 0) {
            var f = this._serialActions[0];
            this._serialActions.removeAt(0);
            this.timer.setTimeout(function() {
                f(my);
            }, 1);
            return this;
        }
        if (this._count <= 0) {
            this.finish();
        }
        return this;
    },
    
    finish: function Awaiter_Await$finish() {
        this._ignore = true;
        this._doAlways(ss.Delegate.create(this, function() {
            if (ss.isValue(this._awp)) {
                this._proxyVars();
                this._awp.done();
            }
        }));
    },
    
    loadAndDo: function Awaiter_Await$loadAndDo(url, className, opts, e) {
        /// <param name="url" type="String">
        /// </param>
        /// <param name="className" type="String">
        /// </param>
        /// <param name="opts" type="Object">
        /// </param>
        /// <param name="e" type="jQueryEvent">
        /// </param>
        /// <returns type="Await"></returns>
        opts = opts || {};
        this.loadScript(url);
        this.addDx(ss.Delegate.create(this, function() {
            try {
                var p = className.split('.');
                var fn = window[p[0]][p[1]];
                fn(e, opts);
            }
            catch (ex) {
                this._error(ex.toString());
            }
        }));
        return this;
    },
    
    loadScript: function Awaiter_Await$loadScript(url, fn) {
        /// <param name="url" type="String">
        /// </param>
        /// <param name="fn" type="System.Action`1">
        /// </param>
        /// <returns type="Await"></returns>
        if (url == null) {
            return this;
        }
        url = url.trim();
        this.addDl(ss.Delegate.create(this, function() {
            if (!Object.keyExists(Await._scripts, url)) {
                var options = {};
                options.url = url;
                options.dataType = 'script';
                options.success = function() {
                    Await._scripts[url] = true;
                };
                options.error = ss.Delegate.create(this, function(request, textStatus, error) {
                    var err = String.format('LoadScript() {0}, {1}, {2}', url, textStatus, error);
                    this._error(err);
                    this.handle(new Error('Blob Load Error: ' + err));
                });
                $.ajax(options);
                Await._scripts[url] = false;
                this._loadScriptWait(url);
            }
            else if (!Await._scripts[url]) {
                this._loadScriptWait(url);
            }
            else {
                this.done();
            }
        }));
        if (arguments.length > 1) {
            this.addAw(fn);
        }
        return this;
    },
    
    loadJson: function Awaiter_Await$loadJson(name, url) {
        /// <param name="name" type="String">
        /// </param>
        /// <param name="url" type="String">
        /// </param>
        /// <returns type="Await"></returns>
        return this.addDl(ss.Delegate.create(this, function() {
            var options = {};
            options.url = url;
            options.dataType = 'json';
            options.type = 'GET';
            options.cache = false;
            options.success = ss.Delegate.create(this, function(data, textStatus, request1) {
                if (name != null) {
                    Await.files[name] = data;
                }
                this.done();
            });
            options.error = ss.Delegate.create(this, function(request, textStatus, error) {
                if (name != null) {
                    Await.files[name] = null;
                }
                var err = String.format('LoadJson() {0}, {1}, {2}', url, textStatus, error);
                this._error(err);
                this.handle(new Error('Blob Load Error: ' + err));
            });
            $.ajax(options);
        }));
    },
    
    loadText: function Awaiter_Await$loadText(name, url) {
        /// <param name="name" type="String">
        /// </param>
        /// <param name="url" type="String">
        /// </param>
        /// <returns type="Await"></returns>
        return this.addDl(ss.Delegate.create(this, function() {
            var options = {};
            options.url = url;
            options.dataType = 'html';
            options.type = 'GET';
            options.cache = false;
            options.success = ss.Delegate.create(this, function(data, textStatus, request1) {
                Await.files[name] = data;
                this.done();
            });
            options.error = ss.Delegate.create(this, function(request, textStatus, error) {
                var err = String.format('LoadText() {0}, {1}, {2}', url, textStatus, error);
                this._error(err);
                this.handle(new Error('Blob Load Error: ' + err));
            });
            $.ajax(options);
        }));
    },
    
    loadCss: function Awaiter_Await$loadCss(url) {
        /// <param name="url" type="String">
        /// </param>
        /// <returns type="Await"></returns>
        return this.addDl(ss.Delegate.create(this, function() {
            if (Object.keyExists(Await.files, url)) {
                this.done();
                return;
            }
            var css = $('<link/>').attr({ rel: 'stylesheet', type: 'text/css', href: url });
            css.appendTo('head');
            if (('styleSheets' in window.document)) {
                var mark = new Date().getTime() + this._maxWaitStyleSheet;
                var tmr = 0;
                tmr = this.timer.setInterval(ss.Delegate.create(this, function() {
                    var sheet = this._hasStyleSheet(url);
                    if (sheet != null || new Date().getTime() > mark) {
                        this.timer.clearTimer(tmr);
                        Await.files[url] = sheet;
                        this.done();
                    }
                }), 5);
            }
            else {
                this.timer.setTimeout(ss.Delegate.create(this, function() {
                    this.done();
                }), 250);
            }
        }));
    },
    
    _hasStyleSheet: function Awaiter_Await$_hasStyleSheet(url) {
        /// <param name="url" type="String">
        /// </param>
        /// <returns type="Awaiter.DynamicStyleSheet"></returns>
        var stylesheets = window.document.styleSheets;
        var $enum1 = ss.IEnumerator.getEnumerator(stylesheets);
        while ($enum1.moveNext()) {
            var sheet = $enum1.current;
            if (!String.isNullOrEmpty(sheet.href) && sheet.href.indexOf(url) >= 0) {
                return sheet;
            }
        }
        return null;
    },
    get_item: function Await$get_item(n) {
        /// <param name="n" type="String">
        /// </param>
        /// <param name="value" type="Object">
        /// </param>
        /// <returns type="Object"></returns>
        return this.vars[(n.substr(0, 1) === '@') ? n.substr(1) : n];
    },
    set_item: function Await$set_item(n, value) {
        /// <param name="n" type="String">
        /// </param>
        /// <param name="value" type="Object">
        /// </param>
        /// <returns type="Object"></returns>
        n = (n.substr(0, 1) === '@') ? n.substr(1) : n;
        this.vars[n] = value;
        this.varsModified[n] = true;
        return value;
    }
}


Timers.registerClass('Timers');
WaitTarget.registerClass('WaitTarget');
Await.registerClass('Await');
Timers._delayedSpinner = 0;
Await.logActions = false;
Await.passExceptions = false;
Await._scripts = {};
Await._simulatedLatency = (([ '192.168.1.19', 'localhost' ]).contains(window.location.hostname)) ? 600 : 0;
Await.files = {};
})();

//! This script was generated using Script# v0.7.4.0
